package keeto.com.vn.bms.network.task;

import java.io.IOException;

import keeto.com.vn.bms.config.IBMSCore;
import keeto.com.vn.bms.network.request.CreateScheduleRequest;
import keeto.com.vn.bms.network.response.CreateScheduleResponse;
import keeto.com.vn.bms.utils.BMSListener;

import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;

public class TaskCreateSchedule extends AbstractTask{
	String authenKey;
	String code;
	String name;
	String Execute_date;
	String Price;
	int Hospital_id;
	String Address;
	String Require;
	int Level;
	int Case_id;
	String AddInfos;
	String TypeCost;
	int SchedUserRole_id;
	int User_id;
	
	
	public TaskCreateSchedule(BMSListener listener, IBMSCore core,
			String authenKey, String code, String name, int User_id, String execute_date,
			String price, int hospital_id, String address, String require,
			int level, int case_id,String AddInfos,String TypeCost, int schedUserRole_id) {
		super(listener, core);
		this.authenKey = authenKey;
		this.code = code;
		this.name = name;
		this.Execute_date = execute_date;
		this.Price = price;
		this.Hospital_id = hospital_id;
		this.Address = address;
		this.Require = require;
		this.Level = level;
		this.Case_id = case_id;
		this.SchedUserRole_id = schedUserRole_id;
		this.AddInfos = AddInfos;
		this.TypeCost = TypeCost;
		this.User_id = User_id;
	}

	@Override
	public void run() throws ClientProtocolException, JSONException, IOException {
		CreateScheduleRequest request = new CreateScheduleRequest();
		request.setAuthenKey(authenKey);
		request.setCode(code);
		request.setName(name);
		request.setExecute_date(Execute_date);
		request.setPrice(Price);
		request.setRequire(Require);
		request.setLevel(Level);
		request.setCase_id(Case_id);
		request.setAddress(Address);
		request.setAddInfos(AddInfos);
		request.setTypeCost(TypeCost);
		request.setSchedUserRole_id(SchedUserRole_id);
		request.setUser_id(User_id);
		request.setHospital_id(Hospital_id);
		CreateScheduleResponse response = protocol.createScheldule(request);
		for (BMSListener mlistener : listener){
			mlistener.finishCreateSchedule(response.getReturnCode(), response.getResultMsg());
		}
	}

	@Override
	public void timeoutCallback() {
		for (BMSListener mlistener : listener){
			mlistener.finishCreateSchedule(protocol.STATUS_CODE_GENERIC_FAIL_CONECTTION, "");
		}
	}

}
